<template>
  <div class="see-template" id="article-content">
    <div class="template">
      <div class="header">
        <span class="title">{{ add == 1 ? "新增渠道" : "编辑渠道" }}</span>
        <i
          @click="closeAddTemplate"
          class="icon iconfont iconguanbi cl-iconfont is-circle"
        ></i>
      </div>
      <el-table
        ref="multipleTable"
        :data="dataList"
        tooltip-effect="dark"
        class="content-table"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection"></el-table-column>
        <el-table-column prop="productName" min-width="100" label="产品名称">
          <template slot-scope="scope">
            <span>{{ scope.row.productName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="productCode" min-width="100" label="产品Code">
          <template slot-scope="scope">
            <span>{{ scope.row.productCode }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="productLevel" min-width="100" label="产品级别">
          <template slot-scope="scope">
            <span>{{ scope.row.productLevel }}</span>
          </template>
        </el-table-column>
        <el-table-column min-width="100" prop="isOnSell" label="产品状态">
          <template slot-scope="scope">
            <span style="padding-right: 8px">{{
              scope.row.status == 1 ? "上架" : "下架"
            }}</span>
            <div
              class="el-switch"
              :class="{ 'is-checked': scope.row.status == 1 }"
              @click="changeProductStatus(scope.row)"
            ></div>
          </template>
        </el-table-column>
        <el-table-column prop="price" min-width="100" label="产品价格">
          <template slot-scope="scope">
            <el-input
              class="contentDetail-title"
              placeholder="请输入产品标题（必填）"
              v-model.trim="scope.row.price"
              show-word-limit
            ></el-input>
          </template>
        </el-table-column>
      </el-table>
      <div class="footer">
        <Debounce :time="1000">
          <button
            class="cl-button cl-button--primary_notbg"
            @click="closeAddTemplate"
          >
            取消
          </button>
        </Debounce>
        <Debounce :time="1000">
          <button class="cl-button cl-button--primary" @click="preservation">
            保存
          </button>
        </Debounce>
      </div>
    </div>
  </div>
</template>

<script>
import * as productManageApi from "@/api/request/productManageApi";
import * as channelProductApi from "@/api/request/channelProductApi";
export default {
  props: ["add", "channelId", "dataItems"],
  data() {
    return {
      params: {
        channelId: Number(this.channelId),
        items: [],
      },
      dataList: [],
      productParams: {
        categoryIdList: [],
        productCode: "",
        productName: "",
        pageIndex: 1,
        pageSize: 10,
      },
      options: [
        {
          value: 1,
          label: "上架",
        },
        {
          value: 0,
          label: "下架",
        },
      ],
      optionsLevel: [
        {
          value: "App",
          label: "App",
        },
        {
          value: "Sib",
          label: "Sib",
        },
      ],
    };
  },
  created() {},
  mounted() {
    this.getList();
  },

  methods: {
    // 请求列表数据
    async getList() {
      this.$Loading.show();
      let { data } = await productManageApi.getList(this.productParams);
      this.$Loading.hide();
      this.dataList = this.filterDelSame(data.items, this.dataItems.items);
    },
    // 遍历数组删除相同对象
    filterDelSame: function (arr1, arr2) {
      let arr3 = [];
      for (var i = 0; i < arr1.length; i++) {
        var flag = 0;
        for (var j = 0; j < arr2.length; j++) {
          if (arr2[j].id == arr1[i].id) {
            flag = 1;
            break;
          }
        }
        if (!flag) {
          arr3.push(arr1[i]);
        }
      }
      return arr3;
    },

    async preservation() {
      let { data, status } = await channelProductApi.postCreate(this.params);

      if (status === 200) {
        this.$notify({
          customClass: "notify-success", //  notify-success ||  notify-error
          message: `编辑成功!`,
          showClose: false,
          duration: 1000,
        });
      } else {
        this.$notify({
          customClass: "notify-error", //  notify-success ||  notify-error
          message: `编辑失败!`,
          showClose: false,
          duration: 1000,
        });
      }
      this.closeAddTemplate();
    },
    /**
     * 单选或全选操作
     */
    handleSelectionChange(list) {
      this.params.items = [];
      list.forEach((k, i) => {
        this.params.items.push({
          price: k.price,
          status: k.status,
          productId: k.id,
        });
      });
    },
    closeAddTemplate() {
      this.$emit("closeAddTemplate");
    },
  },
};
</script>

<style lang="scss" scoped>
form {
  padding: 0 25px;
}
.cl-button--primary_notbg {
  margin-left: 24px;
}
.el-progress-bar__innerText {
  color: red !important;
}
.divProgressa {
  width: 80%;
}
.forProgress {
  margin-bottom: 10px;
}
.seeInformation {
  color: #999999;
  font-size: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.progressTitle {
  display: flex;
}
.divProgress {
  display: flex;
  // justify-content: center;
}
.forContent {
  margin-bottom: 40px;
  padding: 0 20px;
}
.progerss {
  margin-top: 10px;
  margin-bottom: 10px;
}
.progressTitles {
  color: #666666;
  font-size: 14px;
}
.progerssTxt {
  font-weight: bold;
  color: #000;
  font-size: 14px;
  margin-top: 8px;
  margin-bottom: 24px;
}
.divInput {
  color: rgba(102, 102, 102, 1);
  margin-bottom: 8px;
  font-size: 14px;
}
.see-template {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  background: rgba(38, 38, 38, 0.8);
  z-index: 2000;
  .template {
    position: relative;
    margin: 0 0 0 auto;
    height: 100%;
    min-height: 600px;
    width: 600px;
    // padding: 10px 24px 16px;
    box-sizing: border-box;
    background: #ffffff;
    .header {
      display: flex;
      justify-content: space-between;
      border-bottom: $--border-base;
      margin-bottom: 20px;
      span {
        font-size: $--font-size-base;
        color: $--color-text-primary;
        line-height: 44px;
        margin-left: 20px;
      }
      i {
        line-height: 14px;
        padding: 14px;
        height: 14px;
        width: 14px;
      }
    }
    .content {
      .input {
        // display: flex;
        // justify-content: space-between;
        margin-top: 24px;
        // text-align: right;

        span {
          width: 130px;
          line-height: 32px;
          margin-right: 10px;
          .ak-titleIcon {
            color: $--color-danger;
            font-size: 16px;
            vertical-align: middle;
            margin-right: 8px;
          }
        }
      }
      a {
        cursor: pointer;
        display: inline-block;
        margin: 12px 0 0 105px;
        color: $--color-primary;
        font-size: $--font-size-small;
      }
    }
    .save {
      padding-top: 24px;
      div {
        font-size: $--font-size-small;
        color: $--color-text-primary;
        line-height: 18px;
        margin-bottom: 16px;
        span {
          float: left;
          width: 80px;
          text-align: right;
        }
        p {
          margin-left: 80px;
          line-height: 18px;
        }
      }
    }
    .footer {
      position: absolute;
      left: 0;
      bottom: 0;
      height: 64px;
      padding: 16px 0;
      border-top: $--border-base;
      box-sizing: border-box;
      width: 100%;
      background-color: #ffffff;
    }
  }
}
</style>